import 'package:flutter/foundation.dart';

/// 基础控制器，所有需要对外提供controller的widget可以使用这个
mixin DDControllerMixin {
  Map<String, Function(dynamic pars)> _listener = {};

  @mustCallSuper
  void addListener(String name, Function(dynamic pars) func) {
    _listener.addAll({name: func});
  }

  void test() {}

  @mustCallSuper
  void removeListener(String name) {
    _listener.remove(name);
  }

  @mustCallSuper
  void dispatch(String name, dynamic pars) {
    final result = _listener[name];
    if (result != null) {
      result(pars);
    }
  }

  @mustCallSuper
  void dispose() {
    _listener = {};
  }
}
